package com.sardine.base.hbase.session.defaults;

import com.sardine.base.hbase.HBaseConfiguration;
import com.sardine.base.hbase.executor.HBaseExecutor;
import com.sardine.base.hbase.session.HBaseSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.List;

/**
 * 上海京东到家元信信息技术有限公司<br>
 * Created with IntelliJ IDEA.
 * Date:2017/11/20
 * Time:16:19
 * hbase的连接对象
 * @author daifeng<br>
 *         daifeng@imdada.cn
 * @since JDK 1.7 <br>
 * Copyright (c) 2017 imdada System Incorporated All Rights Reserved.
 */
public class DefaultHBaseSession<T> implements HBaseSession {
    private static final Logger logger = LoggerFactory.getLogger(DefaultHBaseSession.class);
    /**
     * hbase的配置中心
     */
    private HBaseConfiguration configuration;
    private HBaseExecutor executor;

    public DefaultHBaseSession(HBaseConfiguration configuration, HBaseExecutor executor) {
        this.configuration = configuration;
        this.executor = executor;
    }

    /**
     * 插入一条记录
     *
     * @param t
     * @return
     */
    @Override
    public boolean insert(Object t) {
        return executor.put(t);
    }

    /**
     * 同步插入一组数据
     *
     * @param t
     * @return
     */
    @Override
    public boolean insert(List<? extends Object > t) {
        return executor.put(t);
    }

    /**
     * 异步插入一组数据
     *
     * @param t
     * @return
     */
    @Override
    public boolean insertAsync(List<? extends Object> t) {
        return executor.putAsync(t);
    }

    /**
     * 查询一条记录rowKey
     *
     * @param rowKey
     * @param aClass
     * @return
     */
    @Override
    public <T> T selectOne(Serializable rowKey, Class<T> aClass) {
        return executor.getOne(rowKey,aClass);
    }

    /**
     * 批量查询一组rowkey
     *
     * @param rowKeyList
     * @param aClass
     * @return
     */
    @Override
    public <T> List<T> selectList(List<? extends Serializable> rowKeyList, Class<T> aClass) {
        return executor.getList(rowKeyList,aClass);
    }
}
